# -*- encoding: utf-8 -*-
# @File    :   user.py
# @Time    :   2021/07/23 15:16:39
# @Author  :   wudongmin
# @Contact :   wudongmin@xroom.net
# @version   :  1.0

from . import RepositoryBase
from app.model.user import User
from app.items import PagniationItem, OrderItem


class RepositoryUser(RepositoryBase):
    # user repository

    def __init__(self) -> None:
        self._user_list_item = [User.id, User.name, User.sex, User.created_at]
        super().__init__()

    def get_user_list(self, page_params: PagniationItem = None, order_params: OrderItem = None) -> tuple([list, int]):
        f = self._session.query(*self._user_list_item)
        count = f.count()

        # 排序
        f = self.sort_filter(f, order_params=order_params)

        # 分页
        f = self.pagination(f, page_params=page_params)
        return f.all(), count
